home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / misc / math / fastprim_src.lzh / fastprim.src
Encoding:
Text File  |  1999-03-23  |  14.3 KB  |  739 lines

  1.  
  2. ;  IMPORTANT NOTE
  3. ;  --------------    
  4.  
  5. ;   This source code is given AS IT IS to the Amiga community, following
  6. ;   a suggestion from Hans Guijt. Explicit permission is given to use it for 
  7. ;   any non-profit purpose, either in parts or as a whole, without any 
  8. ;   further permission from the author. The author himself reserves the right 
  9. ;   to use this source code at any time in the future again. For commercial 
  10. ;   use of this source code, prior written permission from the auther is 
  11. ;   required.
  12.  
  13.  
  14. ;   Contact electronic mail addresses:  grimm@particle.phys.ethz.ch
  15. ;                                       oliver.grimm@desy.de
  16.  
  17. ;   Postal address:     Oliver Grimm
  18. ;                       Steinbecker Str. 69
  19. ;               21244 Buchholz
  20.  
  21. ;               Germany
  22.  
  23.  
  24. ;                                 (Addresses as of March 1999)
  25.  
  26.  
  27. ;  FASTPRIM was written in 1989/1991/1993 by Oliver Grimm    
  28.  
  29. ;
  30. ;  Programmentwicklung: 
  31. ;
  32. ;  V1.0  (? 1989)      - erste Version
  33. ;  V1.1  (April 1991)  - Device-Handling
  34. ;  V1.2  (August 1993) - Bit-Modell; Byte-Modell ca. 15 % schneller;
  35. ;             Zeitmessung; Zählroutine; schnelles Ctrl-c;
  36. ;               variabler Ausgabebeginn; gepufferte Speicherroutine
  37. ;  V1.3  (Sept. 1994)  - Versionsinformation; Datei wird sofort geöffnet
  38.  
  39.  
  40. SysBase = 4
  41.  
  42. LVOOpenLibrary = -552
  43. LVOCloseLibrary = -414
  44. LVOAllocMem = -198
  45. LVOFreeMem = -210
  46. LVOFindTask = -294
  47. LVOSetExcept = -312
  48.  
  49. LVOWrite = -48
  50. LVORead = -42
  51. LVOOpen = -30
  52. LVOClose = -36
  53. LVOOutput = -60
  54. LVODelay = -198
  55. LVODateStamp = -192
  56.  
  57. WRITEBUF = 1000        ; Länge des Schreib-Puffers
  58.  
  59.  
  60.  ; Kommandozeile auswerten
  61.  
  62.  cmp.b     #'-',(a0)    ; wird Bit-Modell erzwungen ?
  63.  bne.s     noBitForce
  64.  move.b     #1,Method
  65.  lea     1(a0),a0
  66.  
  67. noBitForce:
  68.  bsr     GetNum        ; Primzahlen bis wohin berechnen ?
  69.  move.l  d3,Max
  70.  
  71.  bsr     SkipSpace
  72.  
  73.  bsr     GetNum     ; Ausgabebeginn einlesen wenn vorhanden
  74.  move.l  d3,FirstOut
  75.  
  76.  cmp.l     #1,FirstOut    ; FirstOut mindestens 2
  77.  bhi.s     FirstOK
  78.  move.l  #2,FirstOut
  79.  
  80. FirstOK:
  81.  bsr     SkipSpace
  82.   
  83.  cmp.b     #10,(a0)    ; Filename angegeben ? 
  84.  beq.s     noFilename
  85.  
  86.  move.l     a0,Filename
  87. FindLF:    
  88.  cmp.b     #10,(a0)+    ; Linefeed in Null umwandeln
  89.  bne.s     FindLF
  90.  move.b     #0,-1(a0)
  91.  
  92. noFilename:
  93.  move.l  SysBase,a6    ; eigenen Task finden
  94.  sub.l     a1,a1
  95.  jsr     LVOFindTask(a6)
  96.  move.l  d0,Task    ; in ReplyPort eintragen
  97.  
  98.  ;move.l  d0,a0        ; wenn mit RUN gestartet, Abbruch
  99.  ;move.l  172(a0),d0
  100.  ;asl.l     #2,d0        ; BCPL-Zeiger
  101.  ;move.l  d0,a0
  102.  ;move.l  44(a0),d0
  103.  ;beq.s     noRun
  104.  
  105.  ;moveq     #20,d2          ; Rückgabewert in die Shell
  106.  ;bra     Quit
  107.  
  108.  
  109.  ; dos.library öffnen und Ausgabe-Handle besorgen
  110.  
  111. noRun:
  112.  moveq     #20,d2             ; nochmal Rückgabewert, falls dos.library
  113.  lea     DosName(pc),a1      ; öffnen nicht möglich
  114.  moveq     #0,d0
  115.  jsr     LVOOpenLibrary(a6)
  116.  move.l  d0,DosBase
  117.  beq     Quit
  118.  
  119.  move.l  DosBase(pc),a6         ; Ausgabe-Handle ins Fenster
  120.  jsr     LVOOutput(a6)
  121.  move.l  d0,Handle
  122.  beq     noHandle
  123.  
  124.  move.l     Task(pc),a0
  125.  move.l     42(a0),OldExceptCode    ; alten Exceptionzeiger sichern
  126.  move.l     #ExceptCode,42(a0)    ; neuen eintagen
  127.  
  128.  move.l     SysBase,a6 
  129.  move.l     #4096,d0    ; Execptions bei CTRL-c an
  130.  move.l     d0,d1
  131.  jsr     LVOSetExcept(a6)
  132.  
  133. ;   Haupt-Programm
  134.  
  135.  cmp.l   #1,Max       ; wurde überhaupt eine Zahl größer 1 angegeben ?
  136.  bhi.s     CommOK
  137.  move.l  #UsageText,Error
  138.  bra     noMemory
  139.  
  140. CommOK:
  141.  move.l     #MemoryErr,Error
  142.  move.l  Max(pc),d0
  143.  add.l     #8,d0
  144.  move.l  d0,MemLen
  145.  
  146.  tst.b     Method
  147.  bne.s     Bit_forced
  148.  
  149.  move.l  SysBase,a6      ; Speicher allokieren
  150.  move.l  MemLen(pc),d0
  151.  move.l  #65536,d1      ; mit Null initialisieren
  152.  jsr     LVOAllocMem(a6)
  153.  move.l  d0,Memory
  154.  bne.s     GotMem
  155.  
  156. Bit_forced:
  157.  move.b  #1,Method      ; nicht genug Speicher für Quick-Calc
  158.  move.l     SysBase,a6      ; oder Bit-Modell erzwungen
  159.  move.l  MemLen(pc),d0
  160.  asr.l     #3,d0
  161.  move.l  d0,MemLen
  162.  move.l  #65536,d1
  163.  jsr     LVOAllocMem(a6)
  164.  move.l  d0,Memory
  165.  beq     noMemory
  166.  
  167.  
  168. GotMem:
  169.  move.l     #WRITEBUF,d0      ; Save-Puffer allokieren
  170.  move.l     #65536,d1
  171.  jsr     LVOAllocMem(a6)
  172.  move.l     d0,SaveBuf
  173.  beq     noBufMem
  174.  
  175.  clr.l     Error        ; Errorstatus auf Null setzen
  176.  move.l  #StartText,d2
  177.  bsr     Print
  178.  
  179.  
  180.  tst.l     Filename     ; Primzahlen speichern ?
  181.  beq.s     BeginnCalc
  182.  
  183.  move.l     DosBase(pc),a6       ; dann Datei schon jetzt öffnen
  184.  move.l     Filename(pc),d1
  185.  move.l     #1006,d2
  186.  jsr     LVOOpen(a6)
  187.  move.l     d0,FileHandle
  188.  bne.s     BeginnCalc
  189.  
  190.  move.l     #OpenErr,d2
  191.  bsr     Print
  192.  clr.l   Filename
  193.  
  194.  
  195. BeginnCalc: 
  196.  bsr     GetTime      ; Zeitmessung starten
  197.  move.l     d0,Time
  198.  tst.b     Method
  199.  bne.s     Slow
  200.  
  201.  move.l  #FastText,d2      ; Byte-Modell
  202.  bsr     Print
  203.  bsr     QuickCalc
  204.  bra.s     Fertig
  205.  
  206. Slow:
  207.  move.l  #SlowText,d2      ; Bit-Modell
  208.  bsr     Print
  209.  bsr     MemCalc
  210.  
  211. Fertig:
  212.  bsr     GetTime
  213.  sub.l     Time(pc),d0
  214.  add.l     #25,d0
  215.  divu     #50,d0
  216.  ext.l     d0
  217.  move.l     d0,Time
  218.  
  219.  tst.b     Flag          ; Berechnung abgebrochen ?
  220.  beq.s      noAbort
  221.  
  222.  move.l  #AbortText,d2
  223.  bsr     Print
  224.  bra     CloseAll
  225.  
  226.  
  227. noAbort:
  228.  move.l  #ReadyText,d2
  229.  bsr     Print
  230.  
  231.  move.l     #End_of_Count,AbortAdr
  232.  move.l  Memory(pc),a2        ; Primzahlen zählen
  233.  moveq     #1,d2
  234.  move.l     Max(pc),d4
  235.  moveq     #0,d5
  236.  tst.b     Method
  237.  bne.s     CountMem
  238.  
  239.  lea     2(a2),a0
  240.  add.l     Max(pc),a2
  241.  
  242. CountQuick:
  243.  cmp.l     a2,a0
  244.  bhi.s     End_of_Count
  245.  
  246.  tst.b     (a0)+
  247.  bne.s     CountQuick
  248.  addq.l  #1,d5
  249.  bra.s     CountQuick
  250.  
  251. CountMem:
  252.  addq.l  #1,d2
  253.  cmp.l     d4,d2
  254.  bhi.s     End_of_Count
  255.  
  256.  move.l  d2,d0         ; Bytenummer
  257.  asr.l     #3,d0
  258.  move.b  d2,d1         ; Bitnummer
  259.  and.b     #7,d1
  260.  
  261.  bne.s     noSkip        ; wenn Bitnummer 0 und ganzes Byte ist $ff,
  262.  cmp.b     #$ff,0(a2,d0.l)   ; dann 8 Positionen überspringen, da keine
  263.  bne.s     noSkip           ; Primzahl in diesem Byte
  264.  addq.l     #7,d2
  265.  bra.s     CountMem
  266.  
  267. noSkip:
  268.  btst.b  d1,0(a2,d0.l)
  269.  bne.s     CountMem
  270.  addq.l  #1,d5
  271.  bra.s     CountMem
  272.  
  273. End_of_Count:
  274.  clr.l     AbortAdr
  275.  move.l     d5,PrimeNum     ; Anzahl sichern
  276.  
  277.  move.b     Flag(pc),CountFlag
  278.  bne.s     CountOK
  279.  lea     CountText(pc),a2
  280.  bsr     PrintNum
  281.  
  282. CountOK:
  283.  move.l  #CountText,d2
  284.  bsr     Print
  285.  clr.b     Flag
  286.  
  287. Save:
  288.  tst.l     Filename     ; Primzahlen speichern ?
  289.  beq.s     noSave
  290.  
  291.  move.l     #SaveText,d2
  292.  bsr     Print
  293.  
  294.  moveq     #0,d6        ; Primzahlen speichern
  295.  bsr     WritePrim
  296.  
  297.  move.l     #SaveAbText,d2        ; Text Aborted/Done ausgeben
  298.  tst.b     Flag 
  299.  bne.s     notDone
  300.  move.l     #DoneText,d2
  301. notDone:
  302.  bsr     Print
  303.  
  304. noSave:
  305.  clr.b     Flag
  306.  moveq     #1,d6        ; Primzahlen auf Screen ausgeben
  307.  bsr     WritePrim
  308.  
  309.  
  310. ; alle Resourcen wieder schließen
  311.  
  312. End_of_Output:
  313.  lea     EndText+56(pc),a2    ; Anzahl/Zeit ausgeben
  314.  move.l     Time(pc),d5        ; wenn 0, dann 'less than 1' ausgeben
  315.  beq.s     tooShort
  316.  bsr     PrintNum
  317. tooShort:
  318.  tst.b     CountFlag        ; falls nicht gezählt, nur Zeit ausgeben
  319.  bne.s     noCount
  320.  lea     EndText+20(pc),a2
  321.  move.l     PrimeNum(pc),d5
  322.  bsr     PrintNum
  323. noCount:
  324.  move.l  #EndText,d2
  325.  bsr     Print
  326.  
  327. CloseAll:
  328.  tst.l     FileHandle
  329.  beq.s     noFile_to_close
  330.  
  331.  move.l     DosBase(pc),a6        ; Datei schließen
  332.  move.l     FileHandle(pc),d1
  333.  jsr     LVOClose(a6)
  334.  
  335. noFile_to_close:
  336.  move.l  SysBase,a6
  337.  move.l     SaveBuf(pc),a1
  338.  move.l     #WRITEBUF,d0
  339.  jsr     LVOFreeMem(a6)
  340.  
  341. noBufMem:
  342.  move.l  Memory(pc),a1
  343.  move.l  MemLen(pc),d0
  344.  jsr     LVOFreeMem(a6)
  345.  
  346. noMemory:
  347.  move.l     Error(pc),d2    ; eventuell Fehlermeldung/Usage-Text ausgeben
  348.  beq.s     noError
  349.  bsr     Print
  350.  
  351. noError:
  352.  move.l     SysBase,a6 
  353.  moveq     #0,d0        ; Exceptions wieder aus
  354.  move.l     #4096,d1
  355.  jsr     LVOSetExcept(a6)
  356.  move.l     Task(pc),a0           ; alter Exceptionzeiger 
  357.  move.l     OldExceptCode(pc),42(a0)
  358.  
  359.  moveq     #0,d2        ; Rückgabe in Shell: kein Fehler
  360.  
  361. noHandle:
  362.  move.l     SysBase,a6
  363.  move.l  DosBase(pc),a1
  364.  jsr     LVOCloseLibrary(a6)
  365.  
  366. Quit:
  367.  move.l     d2,d0        ; Rückgabewert ins richtige Register
  368.  rts
  369.  
  370. ;
  371. ; ------------------------   Subroutinen  ----------------------------
  372. ;
  373.  
  374. ; Die Zahl, deren ASCII-Darstellung ab der Adresse aus a0 steht, wird
  375. ; in d3 zurückgegeben; a0 zeigt auf das erste Zeichen nach der Zahl
  376.  
  377.  
  378. GetNum:
  379.  moveq     #0,d3
  380.  
  381. GetLoop:
  382.  moveq     #0,d2
  383.  move.b  (a0)+,d2
  384.  sub.b     #'0',d2
  385.  bmi.s     noNumber
  386.  cmp.b     #9,d2
  387.  bhi.s     noNumber
  388.  
  389.  move.l  d3,d1    ; 'mulu #10,d3', aber mehr als 16 Bit benötigt
  390.  asl.l     #2,d1
  391.  add.l     d1,d3
  392.  add.l     d3,d3
  393.  
  394.  add.l     d2,d3
  395.  bra.s     GetLoop
  396.  
  397. noNumber:
  398.  lea     -1(a0),a0
  399.  rts
  400.  
  401.  
  402. ; Die Zahl in d5 wird nach Adresse a2 geschrieben; mit Tab am Ende
  403.  
  404. PrintNum:
  405.  move.l  d5,d2
  406.  lea     1(a2),a1
  407.  moveq     #9,d1
  408.  lea     Table(pc),a0
  409.  
  410. NextDigit:
  411.  moveq     #"0",d0
  412. Dec1:
  413.  addq.b  #1,d0
  414.  sub.l     (a0),d2
  415.  bcc.s     Dec1
  416.  subq.b  #1,d0
  417.  add.l     (a0),d2
  418.  move.b  d0,(a1)+
  419.  lea     4(a0),a0
  420.  dbra     d1,NextDigit
  421.  
  422.  move.l     a2,a0
  423. noZero:
  424.  move.b  #" ",(a0)+     ; führende Nullen löschen
  425.  cmp.b     #"0",(a0)
  426.  beq.s     noZero
  427.  rts
  428.  
  429.  
  430.  ; Textausgabe, in d2 Zeiger auf den Text
  431.  
  432. Print:
  433.  move.l  DosBase(pc),a6
  434.  move.l  Handle(pc),d1
  435.  moveq     #0,d3
  436.  move.l  d2,a0
  437.  
  438. Count:
  439.  addq.l  #1,d3
  440.  tst.b     (a0)+
  441.  bne.s     Count
  442.  subq.l  #1,d3
  443.  jsr     LVOWrite(a6)
  444.  rts
  445.  
  446.  
  447. ; WritePrim gibt alle Primzahlen aus. Ist d6 Null in eine Datei, sonst auf
  448. ; den Bildschirm
  449.  
  450. WritePrim:
  451.  move.l  Memory(pc),a3
  452.  clr.l     BufCnt
  453.  move.l  FirstOut(pc),d5
  454.  subq.l     #1,d5
  455.  
  456. WriteLoop:
  457.  addq.l  #1,d5
  458.  cmp.l     Max(pc),d5
  459.  bhi.s     End_of_Write
  460.  
  461.  tst.b     Method     
  462.  bne.s     MemMethod
  463.  
  464.  tst.b     0(a3,d5.l)
  465.  bra.s     Check
  466.  
  467. MemMethod:
  468.  move.l  d5,d0         ; Bytenummer
  469.  asr.l     #3,d0
  470.  move.b  d5,d1         ; Bitnummer
  471.  and.b     #7,d1
  472.  btst.b  d1,(a3,d0.l)
  473.  
  474. Check:
  475.  bne.s     WriteLoop    ; wenn Byte bzw. Bit Null, dann Primzahl
  476.  
  477.  tst.b     Flag        ; Ctrl-c gedrückt ?
  478.  bne.s     End_of_Write
  479.  tst.b     d6        ; Screen oder Datei ?
  480.  bne.s     Screen
  481.  
  482.  move.l     BufCnt(pc),d0
  483.  move.l     SaveBuf(pc),a0
  484.  move.l     d5,0(a0,d0.l)        ; d5 in Puffer schreiben
  485.  
  486.  addq.l     #4,BufCnt
  487.  cmp.l     #WRITEBUF-6,BufCnt    ; Puffer voll ?
  488.  bls.s     WriteLoop
  489.  bsr     StoreBuf        ; dann sichern
  490.  bra.s     WriteLoop
  491.  
  492. Screen:
  493.  lea     Buffer(pc),a2    ; Primzahl in d5 in Shell ausgeben
  494.  bsr     PrintNum
  495.  move.l  #Buffer+1,d2
  496.  bsr     Print
  497.  
  498.  bra.s     WriteLoop
  499.  
  500. End_of_Write:
  501.  tst.b     d6         ; in Datei, dann restlichen Puffer sichern
  502.  bne.s     noBufFlush
  503.  tst.l     BufCnt
  504.  beq.s     noBufFlush
  505.  bsr     StoreBuf
  506.  
  507. noBufFlush:
  508.  rts
  509.  
  510.  
  511. StoreBuf:
  512.  move.l     DosBase(pc),a6        ; Puffer sichern und Zähler zurücksetzen
  513.  move.l     FileHandle(pc),d1
  514.  move.l     SaveBuf(pc),d2
  515.  move.l     BufCnt(pc),d3
  516.  jsr     LVOWrite(a6)
  517.  
  518.  clr.l     BufCnt
  519.  rts
  520.  
  521.   
  522.  ; GetTime übergibt in d0 die Systemzeit in 1/50 Sekunden
  523.  
  524. GetTime:
  525.  move.l     DosBase(pc),a6
  526.  move.l     #TimeBuf,d1
  527.  jsr     LVODateStamp(a6)
  528.  
  529.  move.l     TimeBuf(pc),d2
  530.  mulu     #24*60,d2        ; Tage in Minuten umrechnen
  531.  add.l     TimeBuf+4(pc),d2    ; Minuten des Tages addieren
  532.  moveq     #0,d0
  533.  move.l     #2999,d1
  534. Min_to_Tick:
  535.  add.l     d2,d0            ; Minuten in Ticks wandeln (*60*50)
  536.  dbra     d1,Min_to_Tick
  537.  add.l     TimeBuf+8(pc),d0    ; Ticks addiereen
  538.  rts 
  539.  
  540.  
  541. ; SkipSpace überspingt alle Spaces,Tabs,Shift-Spaces ab Adresse a0
  542.  
  543. SkipSpace:
  544.  lea     1(a0),a0
  545.  cmp.b     #32,-1(a0)    ; Space
  546.  beq.s     SkipSpace
  547.  cmp.b     #160,-1(a0)    ; Shift-Space
  548.  beq.s     SkipSpace
  549.  cmp.b     #9,-1(a0)    ; Tab
  550.  beq.s     SkipSpace
  551.  
  552.  lea     -1(a0),a0
  553.  rts
  554.  
  555.  
  556. ; Exception-Handler wird aufgerufen, wenn CTRL-c gedrückt
  557.  
  558. ExceptCode:
  559.  move.l     AbortAdr(pc),d1   ; Rücksprungadresse in Task ändern,
  560.  beq.s     noAdress        ; wenn gewünscht
  561.  move.l     Task(pc),a0
  562.  move.l     54(a0),a0    ; Zeiger auf Stack
  563.  move.l     d1,(a0)    ; PC ändern
  564. noAdress:
  565.  move.b     #1,Flag
  566.  rts
  567.  
  568.   
  569. ;
  570. ; --- Es folgen die beiden Berechnungsroutinen ---
  571. ;
  572.  
  573. ; 1.) maximale Geschwindigkeit
  574.  
  575. QuickCalc:
  576.  move.l     #QuickEnd,AbortAdr    ; für Exception
  577.  
  578.  move.l  Memory(pc),a0
  579.  move.l  Max(pc),d2
  580.  move.l  a0,a2
  581.  add.l     d2,a2        ; oberes Ende der Liste
  582.  moveq     #2,d0
  583.  
  584. QuickWeiter:
  585.  move.l  d0,d1
  586.  mulu     d1,d1
  587.  cmp.l     d2,d1
  588.  bhi.s     QuickEnd    ; Algorithmus beenden
  589.  
  590.  move.l  a0,a1        ; alle nicht-Primzahlen markieren
  591.  add.l     d0,a1
  592.  bra.s     QuickLab
  593. QuickLoop:
  594.  move.b  #1,(a1)
  595. QuickLab:
  596.  add.l     d0,a1
  597.  cmp.l     a2,a1
  598.  bls.s     QuickLoop
  599.  
  600. QuickSuche:
  601.  addq.l  #1,d0
  602.  tst.b     0(a0,d0.l)
  603.  bne.s     QuickSuche
  604.  bra.s     QuickWeiter
  605.  
  606. QuickEnd:
  607.  clr.l     AbortAdr
  608.  rts
  609.  
  610. ; 2.) Speichersparend ; benötigt nur 1/8 des Speicherplatzes
  611.  
  612. MemCalc:
  613.  move.l     #QuickEnd,AbortAdr
  614.  
  615.  move.l  Memory(pc),a0
  616.  move.l  Max(pc),d2
  617.  moveq     #2,d0
  618.  
  619. MemWeiter:
  620.  move.l  d0,d1
  621.  mulu     d1,d1
  622.  cmp.l     d2,d1
  623.  bhi.s     QuickEnd      ; Algorithmus beenden
  624.  
  625.  move.l  d0,d1           ; alle nicht-Primzahlen markieren
  626.  bra.s     MemLab
  627.  
  628. MemLoop:
  629.  move.l  d1,d4         ; Bytenummer
  630.  asr.l     #3,d4
  631.  move.b  d1,d3          ; Bitnummer
  632.  and.b     #7,d3
  633.  bset.b  d3,(a0,d4.l)
  634. MemLab:
  635.  add.l     d0,d1
  636.  cmp.l     d2,d1
  637.  bls.s     MemLoop
  638.  
  639. MemSuche:
  640.  addq.l  #1,d0
  641.  move.l  d0,d1
  642.  asr.l     #3,d1
  643.  move.b  d0,d3
  644.  and.b     #7,d3
  645.  btst.b  d3,0(a0,d1.l)
  646.  bne.s     MemSuche
  647.  bra.s     MemWeiter
  648.  
  649.  
  650.  ;
  651.  ; --- Datenbreich ---
  652.  ;
  653.  
  654. Version: dc.b "$VER: FastPrim 1.3 (9.9.1994)",0
  655.  
  656.  
  657. DosName: dc.b "dos.library",0
  658.  
  659. StartText:
  660.  dc.b 10,$9b,"33;1mFASTPRIM V1.3"
  661.  dc.b $9b,"0;33m by Oliver Grimm",10
  662.  dc.b "Written 1989-1994  -  All rights reserved.",$9b,"0m",10,10,0
  663.  
  664. FastText:
  665.  dc.b "Calculating prime numbers using fast byte model ...",10 
  666.  dc.b "Press Ctrl-c to abort.",10,10,0
  667.  
  668. SlowText:
  669.  dc.b "Calculating prime numbers using memory-efficient bit model ...",10 
  670.  dc.b "Press Ctrl-c to abort.",10,10,0 
  671.  
  672. UsageText:
  673.   dc.b 10,$9b,"1mUsage:",$9b,"22m Fastprim",$9b,"33m [-]Number [Number] [Filename]",$9b,"0m",10,10
  674.   dc.b "Parameters in [] are optional.",10
  675.   dc.b "The first number determines the upper limit of calculation, the optional",10
  676.   dc.b "minus sign forces the use of the bit model (see doc file). Output will",10
  677.   dc.b "begin with the first prime number equal or higher than the second number.",10
  678.   dc.b "Furthermore, prime numbers can be stored in the file given by FILENAME.",10,10,0
  679.   
  680. ReadyText: dc.b "Calculation complete  -   Number of Prime's:",0
  681. CountText: dc.b "  -------   ",10,10,0
  682.  
  683. EndText: dc.b 10,10,"Number of Prime's:  -------         Calculation time: less than 1 s",10,10,0
  684. AbortText: dc.b 10,10," --- Calculation terminated ---",10,10,0
  685.  
  686. SaveText: dc.b "Writing prime numbers to file ...       ",0
  687. DoneText: dc.b "Done.",10,10,0
  688. SaveAbText: dc.b "Aborted.",10,10,0
  689.  
  690.  
  691. OpenErr: dc.b "Unable to open file, no prime numbers will be stored.",10,10,10,0 
  692. MemoryErr:  dc.b "Error: Insufficient free store",10,10,0
  693. DeviceErr:  dc.b "Error: Unable to open input device",10,10,0
  694. HandlerErr: dc.b "Error: Unable to install input handler",10,10,0
  695.  
  696.  
  697. Method: dc.b 0        ; Null, wenn QuickCalc
  698. Flag: dc.b 0        ; Ctrl-c Handler-Flag
  699. CountFlag: dc.b 0    ; Endtext unterdrücken, falls zählen nicht fertig
  700.  
  701.  even
  702.  
  703. Task:           dc.l 0
  704. DosBase:       dc.l 0
  705. OldExceptCode: dc.l 0
  706. Handle:        dc.l 0
  707.  
  708. Memory:    dc.l 0     ; Zeiger auf Primzahl-Speicher
  709. MemLen:    dc.l 0     ; dessen Länge
  710. SaveBuf:   dc.l 0    ; Puffer für Save-Funktion
  711. BufCnt:       dc.l 0    ; aktuelle Position in Puffer
  712.  
  713. Filename:    dc.l 0    ; Zeiger auf Filenamen, wenn Speichern gewünscht
  714. FileHandle:  dc.l 0
  715.  
  716. Buffer: ds.b 11         ; für Primzahl-Ausgabe
  717.     dc.b 9,0    ; Tabulator
  718.         
  719. TimeBuf:   ds.l 3    ; für DateStamp
  720. Time:       dc.l 0
  721.  
  722. Max:      dc.l 0    ; Primzahl-Obergrenze
  723. FirstOut: dc.l 0
  724. PrimeNum: dc.l 0    ; Anzahl der Primzahlen
  725.  
  726. AbortAdr: dc.l 0    ; Zieladresse bei Ctrl-c
  727. Error: dc.l 0        ; Adresse des Fehlertextes oder NULL
  728.  
  729. Table:
  730.  dc.l 1000000000
  731.  dc.l 100000000
  732.  dc.l 10000000
  733.  dc.l 1000000
  734.  dc.l 100000
  735.  dc.l 10000
  736.  dc.l 1000
  737.  dc.l 100
  738.  dc.l 10
  739.  dc.l 1